<script setup lang="ts">
import {CirclePlusFilled, House} from "@element-plus/icons-vue";
import {onMounted, ref} from "vue";
import {getGenerator} from "@/utils/generator";
import {useLoginStore} from "@/stores/userStore";

const userStore = useLoginStore()

const select = ref({
  current: 1,
  description: '',
  pageSize: 12,
  sortField: 'createTime',
  sortOrder: 'descend',
  name: '',
  searchText: ''
})
const search = ref({
  current: 1,
  pageSize: 12,
  sortField: 'createTime',
  sortOrder: 'descend',
  id: ''
})

const reset = () => {
  select.value.description = ''
  select.value.name = ''
  select.value.searchText = ''
}

const submit = async () => {
  search.value.id = userStore.id
  const res = await getGenerator(search.value)
  console.log(res.data.data)
}

onMounted(() => {
  submit()
})
const data = ref([])
</script>

<template>
  <div class="common-layout">
    <el-container>
      <el-header>
        <div class="header">
          <img src="@/assets/logo.svg" alt="鱼籽代码生成器">
          <span>鱼籽代码生成器</span>
        </div>
        <div class="nav-links">
          <div class="nav-item">
            <el-icon><House /></el-icon>
            <span>主页</span>
          </div>
          <div class="nav-item">
            <el-icon><CirclePlusFilled /></el-icon>
            <span>创建生成器</span>
          </div>
        </div>
        <div class="start-use">
          <div class="button-group">
            <el-button type="primary" class="action-btn">
              <router-link to="/login" class="btn-link">登录</router-link>
            </el-button>
            <el-button type="success" class="action-btn">
              <router-link to="/register" class="btn-link">注册</router-link>
            </el-button>
          </div>
        </div>
      </el-header>
      <el-main>
        <el-input v-model="select.searchText" style="width: 240px" placeholder="搜索代码生成器" />
        <el-button type="primary">搜索</el-button>
        <hr>
        <span>名称：</span> <el-input v-model="select.name" style="width: 240px" placeholder="请输入名称" />
        <span>描述：</span> <el-input v-model="select.description" style="width: 240px" placeholder="请输入描述" />
        <el-button type="primary" @click="reset">重置</el-button>
        <!--       生成器数据展示 -->
        <div class="data">
          <ul v-infinite-scroll="load" class="infinite-list" style="overflow: auto">
            <li v-for="i in count" :key="i" class="infinite-list-item">{{ i }}</li>
          </ul>
        </div>
      </el-main>
      <!-- Footer Content -->
      <el-footer class="footer">
        <div class="footer-content">
          <a href="https://gitee.com/wangfenghuan3399/yuzi-generator" target="_blank" class="footer-link">
            <img src="@/assets/gitee.svg" alt="Gitee开源仓库" class="gitee-logo">
            <span class="footer-text">鱼籽代码生成器-Gitee 开源仓库</span>
          </a>
        </div>
      </el-footer>
    </el-container>
  </div>
</template>

<style scoped lang="less">
.common-layout {
  height: 100vh;

  .el-container {
    height: 100%;

    .el-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      background: white;
      box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
      padding: 0 40px;
      border-bottom: 1px solid #eee;

      .header {
        display: flex;
        align-items: center;
        gap: 12px;

        img {
          height: 40px;
          transition: transform 0.3s;

          &:hover {
            transform: rotate(-10deg);
          }
        }

        span {
          font-size: 20px;
          font-weight: 600;
          color: #333;
          letter-spacing: 1px;
        }
      }

      .nav-links {
        display: flex;
        gap: 30px;
        margin-left: 40px;

        .nav-item {
          display: flex;
          align-items: center;
          gap: 8px;
          cursor: pointer;
          color: #666;
          transition: all 0.3s;
          padding: 8px 12px;
          border-radius: 4px;

          &:hover {
            color: #409eff;
            background: #f5f7fa;

            .el-icon {
              transform: scale(1.1);
            }
          }

          .el-icon {
            font-size: 18px;
            transition: transform 0.3s;
          }

          span {
            font-size: 15px;
            font-weight: 500;
          }
        }
      }

      .start-use {
        .button-group {
          display: flex;
          gap: 15px;

          .action-btn {
            padding: 8px 20px;
            transition: all 0.3s;

            &:hover {
              transform: translateY(-2px);
            }

            .btn-link {
              color: inherit;
              text-decoration: none;
              font-weight: 500;
              letter-spacing: 0.5px;
            }
          }
        }
      }
    }

    .el-main {
      background: #f8fafc;
      padding: 30px;
      min-height: calc(100vh - 60px);
    }
  }
}
</style>
